using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region Agreement

	/// <summary>
	/// Agreement object for NHibernate mapped table 'Agreement'.
	/// </summary>
	[Serializable]
	public class Agreement : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected Nullables.NullableDateTime _lastLoginTime;
		protected Employee _employee;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public Agreement() { }

		public Agreement( Nullables.NullableDateTime lastLoginTime, Employee employee )
		{
			this._lastLoginTime = lastLoginTime;
			this._employee = employee;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public Nullables.NullableDateTime LastLoginTime
		{
			get { return _lastLoginTime; }
			set { _lastLoginTime = value; }
		}

		public Employee Employee
		{
			get { return _employee; }
			set { _employee = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is Agreement))
				throw new InvalidCastException("This object is not of type Agreement");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((Agreement)obj).Id);
					break;
				case "LastLoginTime":
						relativeValue = ( this.LastLoginTime != null ) ? this.LastLoginTime.CompareTo(((Agreement)obj).LastLoginTime) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (Agreement.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
